package com.zx.mes.hyl.upms.dao;

import com.zx.mes.hyl.upms.model.Tuser;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author hyl
 * @date 2017-11-25
 */
public interface UserRepository extends JpaRepository<Tuser,String> ,JpaSpecificationExecutor<Tuser> {

    Tuser findBy(String name);

    List<Tuser> findByUs(String name, Pageable pageable);

    Tuser findByNameAndPwd(String name, String pwd);

    @Query("select distinct t from Tuser t left join fetch t.troles role where t.id = :id")
    Tuser getByUserId(@Param("id") String id);


    @Query("select distinct t from Tuser t left join fetch t.troles role where t.name = :userName")
    Tuser getByUserName(@Param("userName") String userName);

    @Query("select t from Tuser t join fetch t.troles role join fetch role.tresources resource where t.id = :id")
    Tuser getResourceByUserId(@Param("id") String id);
}
